Added write_csv function.