How does the digital compass "figure of eight" waving for calibration work?
The reason for moving your device in a figure eight is to help it calibrate itself against magnetic interference. By moving it slightly its able to detect the differences and return a more accurate reading. 

You can read the Apple knowledge base article here