Flatten dataset on the fly in `save_to_disk`
Flatten a dataset on the fly in `save_to_disk` instead of doing it with `flatten_indices`  to avoid creating an additional cache file.

(this is one of the sub-tasks in https://github.com/huggingface/datasets/issues/5507)