If you are running on Windows, shouldn't you set $\ = "\r\n"; in your code?
In reply to Re: corrupted print output by onelesd in thread corrupted print output by weston2010