compute and write file together