using writeFile close event instead of finish