fixed overwriting output file