in reply to open file does not work for externally defined filename

Let Perl tell you what the error is.

open my $fh, '>>', $file or die "Can't append to '$file': $!";

Note the use of three argument open and $! to get the error (see perlvar).