libcollectdclient: Check if the file handle is valid before writing to it.