The flirting is absolutely fine. As some previous posters pointed out, without dishonest intentions, it can even be healthy in some ways.
It's a bad situation all around, and there's really no right choice. On one hand, if you want a relationship with girl B, it would seem like an obvious solution would be to break up with girl A and go out with girl B, but any girl who's actually WORTH dating will be perceptive enough to wonder if she's disposable, too, the next time you get distracted by something else shiny.
If you cheat on girl A with girl B, then that's unequivocally bad.
I would recommend being honest in this case. Tell girl B you're going out with girl A and you're not cheater. Tell girl A what happened and that even though you might have been tempted, your willpower won out and you wouldn't cheat. Either she admires you for being honest, or she breaks up with you for even being tempted (which would be ridiculous, since it happens to everyone - this has the added bonus of finding out if girl A has a good head on her shoulders). If girl A breaks up with you, tell girl B and she'll probably sympathize and it will make you look fairly good in that you were honest with both parties, and something might even come of it. The problem with this whole strategy is that while it's outwardly honest, it's also sort of manipulative when you think it out that way. Motives matter.