Prevent vars from leaking into our env

Shell variables are global by default. If they're not declared with `local` they will leak into our environment which introduces a couple of weird bugs.