use fwrite() instead of write() for file io