BUG:close file when output is done