Notice how the number within the badness sub is increasing for each process, but the $foo that is seen by the instance script is never modified after 'badness' after the first execution for that process.

This is because the badness function is actually an inner function now,
and it keeps a reference to the instance of $foo that was created for the
first run.

Edit - example of how to avoid this issue added, per rhesa's suggestion

Thankfully it is easy to avoid these problems once you know why they occur.
Tips: