Serial.flush(); // clear serial port
Which version of the IDE are you using? There is a 99.999% chance that this code does NOT belong in your sketch.
Opening the serial port resets the Arduino. Closing the serial port resets the Arduino. Is it really necessary to reset the Arduino so often?
If Serial.read() is how you get serial data from the PC, what would you guess is the function to print or write data to the serial port for the PC to read?