TOOLS/lua/autoload: don't shadow local variable

"dir" is already used somewhere above. This was ok, but not nice.
TOOLS/lua/autoload: fix operation outside of working dir

Fixes #1222. (This commit is based on a patch posted there.)