Made the env_ and doc_ variables always use export rather than local and
removed the --global-env option.
Add pipe to sort when writing env.log to make it easier to
inspect the environment variables.