Can someone confirm that i must comment out those lines of code when the arduino is not connected to a computer's serial port?
No, Serial.print() does not make problems if there is no connection to the PC. If you get such problems the error is somewhere else in your code. Post your code if you need help with it.