Actually, we're not talking about STEM in general, we're talking about computer programming in particular. As I was reading this thread, I was just thinking about how other parts of the STEM community aren't nearly so bad.
For instance, if you go hang out in your local university's maths (or physics) department, you'll find many of the same conditions. You'll find an overwhelmingly male group, ranging from slightly nerdy to very nerdy, with a sprinkling of a few women. But you won't find these sorts of problems occurring nearly so often.
Why? I think it's part of a culture of professionalism vs unprofessionalism, and it's largely age-driven. A university department is dominated (socially if not numerically) by people in their forties and fifties, giving the workplace a much older, quieter, more professional feel than you get in a tech company where just about everybody is in their twenties. It's just a matter of having plenty of adult supervision around, I think.
Linux user groups are even worse. They combine the worst features of a party (a lack of professionalism) with the worst features of a high tech workplace (a twenty-to-one sex ratio) so it's not surprising that bad things can happen there.