add hClose to writeBinaryFile