Serial Print makes code work. Why?

Serial.print could be acting as a delay. Did you try to comment out the serial print and put in a delay() in its place?