Dont write directly to files but rather write and copy a tmp file