Why do MEGA2560 digital pins go high on serial disconnect?
When you connect and disconnect from the Arduino, the usb host chip resets the entire device. If you do not want this you can cut the RESET trace on the board.


some boards have a jumper here instead that can be removed.

more info here

https://playground.arduino.cc/Main/DisablingAutoResetOnSerialConnection