Line endings in SMTP are \x0D\x0A, and you're sending only \n (assuming that you are on Unix).
Is there any reason you are not using one of the SMTP modules?
I'm also not sure what the SMTP spec says about repeated HELO commands.
Have you used a network sniffer to check what actually goes over the wire? Maybe the remote end closed the connection or simply stops talking to you if you behave in a way that does not conform to the SMTP spec. Is there an error log at the remote end that you can inspect?