That's a no win situation that I've been on both sides of.
You're damned if you do tell, ...and you're damned if you don't.
I had a friend whose bf was cheating, ...and I told her. She didn't believe me and got mad at me for saying something. Another time when I busted a guy for cheating, he tried to get himself out of shit by lying to his gf saying that I had hit on him, ...he even got his friend to lie for him as well saying he was there, and witnessed me hitting on him, so when I told her, she accused me of making it all up due to sour grapes from being turned down.
She eventually found out the truth, but the grief she put me through destroyed the friendship.
I've seen situations where people went along in blissful ignorance, and when told the truth about a cheating spouse, the pain lingered and interfered with their relationship, ...and it is frequently the messenger who gets the blame.
I once had a gf tell me the guy I was seeing was secretly married, and that his wife lived in LA quietly out of the limelight.
When I asked him about it, he denied it till he was blue in the face. Who was I to believe? Surely if he was married, I would have heard mention of it in the tabloids or something? I took his word over hers, and chalked it up to jealousy on her part. Sure enough, one day she called me informing me that she had just heard through the grape vine his wife just flew into Toronto that morning. Well wouldn't ya know, despite the fact that there were some very important must-attend film industry galas here in Toronto that weekend, he called me that afternoon and said he just out-of-the-blue felt like getting out of town, and wouldn't it be great to fly to New York City on the spur of the moment catching a show on Broadway or something... needless to say I dumped his butt on the spot. I should have known better. The girl who told me was extremely well connected and always seemed to know where everyone else's skeletons were buried. The very fact that she even knew of our relationship to begin with should have reminded me of her frequent access to information not readily known by others. She's also very pragmatic and would never be morally outraged by cheating souses since she herself was a serial dater of married men. She simply told me because she knew I was personally avverse to the idea of being involved with a married man, ...and she knew I would want to know.
Then there was the time I knew a friends bf was cheating, ...and I never told her.
Well she eventually found out, and didn't talk to me for months because I knew and didn't tell her.
I say play it by ear, ...and know who you're dealing with.
If your friend is the type that would want to know, ...tell them. But be prepared for the backlash.
If not, keep your mouth shut, and hightail it out of their before either of them sees you.
But if the friend flaunts the affair infront of you, ...tell them off for being so selfish, and inconsiderate, as to put you in the middle of such an uncomfortable situation.