Use close event and fs.writeFile