Re #9351. Move computation of what output filename will be.

Putting it before the algorithm call gives us a better chance of getting
it right if the algorithm runs over midnight.