I had a similar problem years ago. A server was communicating with several clients, but sometimes one line of the communication got lost somewhere. The sleep solution solved the problem, but even then I was not 100% sure the error did not occur rarely, time to time.
Re: poorly documented behaviour of readline() and IO::Select
Download Code Replies are listed 'Best First'.