Fix ARTIFACT env-var being replaced if only one entry is listed.

Also, use WriteEnv.