Implements writing csv file.