Optional writing to file