in reply to Can't write to open writeable Filehandle

without looking through all of your code: not only open can fail, but also print and close (for example if the partition is full).

You could check for that: use Fatal qw(:void print close);