in reply to syscall() closes file descriptor

I think you want fileno($f). Your system wouldn't know what to do with a Perl file handle.

Update: I got the arguments wrong. $f is being passed as the buffer. Maybe the buffer gets overwritten during the writting process? Or even more likely, maybe something along the lines of $f = "$f"; happens? Both would close the file handle because $f would become a normal string instead of a file handle.