added code to write all items to a file