to_csv regression in 0.23.1
Writing to gzip no longer works with 0.23.1:
```
with gzip.open('test.txt.gz', 'wt') as f:
    pd.DataFrame([0,1],index=['a','b'], columns=['c']).to_csv(f, sep='\t')
```
produces corrupted output. This works fine in 0.23.0.

Presumably this is related to #21241 and #21118.