Thank you for the clarification.
But you never showed us parts of your code -- the hashbang, if any, and the use IO::Handle;. That would have forestalled my concern about the appearance of printflush without a predicate. Discipulus sussed that out, but obviously, I didn't... and, in any case, we often see problems such as using a function from a module without useing the module. Those cases make it very hard to help if the code presented isn't an exact copy of the code which generated anomalies or errors.
BTW, the preceding para may have some value for you but I hope it also provides some benefit for future newcomers who stumble upon it.
And, as has already been said, welcome to PM.