There's nothing wrong with the PERL code. First off, I would check and make sure that the path is correct. Remove all folders and just write to a text file on the root. See where it goes.

After that I would check for a rights issue.