If possible, do not write them all in the same directory. Many file systems slow down when working with directories containing a large number of files. (I once brought our file server to work, which usually gladly serves the entire office, to my knees, writing thousands of files to the same directory).
Instead, create a new directory for every 1000 files or so.
source
share