Make main async; Close file after write.