As far as I can read session.sys.config.getenv is expecting an Array, not an String, and String doesn't provide an #each method:

https://github.com/rapid7/metasploit-framework/blob/master/lib/rex/post/meterpreter/extensions/stdapi/sys/config.rb#L43

Just reading the code under session.sys.config.getenv, not tested, maybe I'm wrong and I'm forgetting something. Sorry about that if I'm wrong.