Are you a real friend? Are you going to look out for your friend even if it's risky for you? If not then just don't worry about it.
If you really are her friend, bring it up to her. I'd wait until they were both there and let it rip that he was being all flirty with you and touching you in ways he shouldn't be. Let it be known right there that he has no chance with you, because no one who acts like that with other girls when he has a girl friend does. Say you have struggled with that and decided to air it out and let them deal with it together, then tell your girl friend you are sorry it had to come out like that and to call you anytime and you can talk, excuse yourself, and let them deal with it. Either that or just tell her.
There is no win in this situation, just do what is best for your friend and understand that a situation like this just sucks and if she is your friend she will understand. Let it go on and you have more chance that she will hate you sooner or later. I wish there was something magical I could tell you, but a situation like this is just a mess and there is no way you will come out perfect, especially since you didn't say something right away.
cutting your losses in a no win situation is as close as you get to a win, it's about how your girl friend takes it, which might tell you how much of a true friend she is as well