Review the original item:
Mike has terrible eating habits when he opened
his lunch bag, we saw a bag of potato chips, two candy bars, cellophane-wrapped
cupcakes, and a carton of chocolate milk.
You wanted to fix it this way:
Mike has terrible eating habits,
when he opened his lunch bag, we saw a bag of potato chips, two candy
bars, cellophane-wrapped cupcakes, and a carton of chocolate milk.
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.