Avoid blowing up the stack by using `setImmediate()` instead of recursion

I've bumped into #83 while trying to optimize a folder with ~500 images. Using the proposed fix (but with `setImmediate` instead of `setTimeout`) solved the issue for me.

All tests are passing.