new implementation of file_write