Thanks Noam.
The problem seems to be with setenv.
The following is a possible fix.
diff --git a/lisp/env.el b/lisp/env.el
index 859f280802..c93be80e84 100644
--- a/lisp/env.el
+++ b/lisp/env.el
@@ -105,7 +105,7 @@ setenv-internal
"Set VARIABLE to VALUE in ENV, adding empty entries if KEEP-EMPTY.
Changes ENV by side-effect, and returns its new value."
(let ((pattern (concat "\\`" (regexp-quote variable) "\\(=\\|\\'\\)"))
- (case-fold-search nil)
+ (case-fold-search (memq system-type '(ms-dos windows-nt))
(scan env)
prev found)
;; Handle deletions from the beginning of the list specially.