performance improvements

Eliminates most of the IO due to writing files incrementally.

Moves file-count cache to temp folder so it can be re-used across
runs. Previously it was kept in the output folder, which can change.