in reply to Failed to create a file

Read the documentation for open. You're currently trying to open for reading instead of writing.

Also, give yourself all the debugging information possible in your die statements. It would've told you what was wrong.

my $file = "C:\\TEMP\\cfg"; open CFG, '>', $file or die "failed to open $file: $!";