handle the None case when writing to a file