There's a related question on Seasoned Advice.

When you boil some food like pasta or legumes without the lid, there's almost no foam, but when you put it on, the foam quickly builds up and runs over the edges. When you remove the lid, it disappears almost immediately. Why?