in reply to Detecting write errors (disk full, bad media)

And you can easily check this if you close the filehandle before printing "CCC".

print $fh "CCC\n" or die "The file has vanished.";

will returns something like "print() on closed filehandle $fh at ... line ... The file has vanished. at ... line ..."