Are you reading the files from the current directory? If you print
$i, is there an absolute path to the file as in your last example? If it's a relative path (or just the file name), maybe you need to
chdir to the appropriate directory first, or prepend the correct path to the file name.