Make modules set a valid working directory

Fixes #6546