Immediately write and close file