My guess is this part of code waits for serial port to get ready, and since your laptop is not connected to the unit, it waits indefinitely. Try this variation instead:
unsigned long startTime = millis();
while (!Serial && (millis() - startTime < 5000)) {
}
This would wait for 5 seconds for serial port before continuing.