in reply to Writing to a file
But file contains '?' in the filename
$filename contains a \n that you should chomp.