Best Intentions, Ironic Results
The humor in shows like The Office and Curb Your Enthusiasm usually arises out of their protagonists' penchant for saying or doing the most inappropriate thing possible in a given situation. But how does this work in real life?
In his article, "How to Think, Say, or Do Precisely the Worst Thing For Any Occasion," Daniel M. Wegner, the John Lindsley Professor of Psychology in Memory of William James, suggests that our blunders have to do with something called "the ironic process of mental control."
When we actively strive to avoid some thought or action, the mental processes that watch for mistakes can sometimes backfire on us, actually increasing our chances of making just such mortifying mistakes. This is especially true when we're distracted or under pressure.
You can find a complete list of Prof. Wegner's work in DASH here.