When saving the file are you using binmode?
Also I notice this is your first post (under this username), if you have not done so already please read the PerlMonks FAQ and How do I post a question effectively?. Using code tags when posting code make it easier for us to read your posts.