in reply to Odd behaviour from print statement

You could try checking the return value of print, as it will return true on success and false on failure.

May the Force be with you