Write file from a buffer