in reply to problem with naming the file with current date and time

The filename you get from my $filename=<STDIN> has a newline at the end. You need to remove this, for example by doing a chomp $filename.