Made the write to CSV conditional.