First: Why do you or would you flirt?
You don't flirt with members of the same sex, so it's not a matter of trying to be funny or witty.
Answer that one, and further answers will follow.
A lot of people have trouble "turning it off" when married because of the very bad way we mate in the West, and the US in particular.
In the West, we commonly mate on the basis of pure dumb luck, absolute chance. We expect that somehow we will just stumble blindly into "the one," and therefore we must always be trying out every possibility. It's like being a door-to-door salesman.
We start this behavior out at a very young age, even before we intend to follow through.
In my teen male Church group, one boy admitted that he'd started having sex with his girlfriend. I asked him if she knew he planned to break up with her. He said, "I'm not planning to break up with her!" I replied, "Are you planning to marry her? No? Then you're planning to break up with her."
So what is the purpose of flirting?