Take another look at the original sentence:
You wanted to fix it this way:
To add a comma between habits and when would cause an equally bad problem, a comma splice. A comma splice occurs when you have two complete sentences joined with just a comma. Mike has terrible eating habits is the first sentence. When he opened his lunch bag, we saw ... starts the second sentence. The spot between habits and when needs a stronger break than a wimpy comma.
You might want to consult the rules for fixing comma splices and fused sentences.