Well the exact scientific reason is still not surely known but this phenomenon probably occurs due to bubble formation in the beer which triggers crystallization at a partiuclar low temperature!

It is a cool party trick anyhow!!