fix file is written only if empty at start