When I inspect my requests in Mozilla the files are present in each one correctly. The unless statement should be correct. I also tried if (scalar @attachments == 0) with the same results. I don't exactly know how should I use Data::Dumper but when I do the first request after restart the file is present and I can open and copy its content normally.