You have a syntax error (strictures would warn you of this): open( my $filehandle, '>>', $theTime ) or die "failed to open file $theTime: $!";
Additionally, you might find it easier to generate that timestamp with a module like DateTime: my $time = (join '_', map { $_->hour, $_->day_abbr } DateTime->now) . '.txt';
Comment on Re: printing to file, which is a variable