Add export_env_dir function and tests