make sure outdir exists and open outfile again