Writing object individually to the file instead of in a list