This type of problem happens a lot when writing batch scripts. It's called delayed expansion.
Basically the command processor replaces environment variables before the command is executed. Since you are setting a variable with the first command, the second command still uses the "initial" value of the variable (which didn't exist when executed). Since you are combining both commands into one, the use of the variable set by the first command isn't being used in the second command.
When you open the command prompt (cmd.exe), I am betting that it is enabling delayed expansion by default, which is why it works.
There are 3 ways to fix this depending on your overall goals.
The easiest solution would be to just utilize the OutputFile option and forget about setting any temporary environment variable.
This also has the advantage of using the output of the command as the string value of the measure so you can display it in your skins. Space
Use the call command. Normally this command is used to call other batch scripts, but you can use it to call a "subroutine". This might not work for other cases, so this method isn't fully recommended.
The proper solution is actually to enable delayed expansion as a command line switch to the cmd process - and subsequently to use the delayed expansion syntax ( ! instead of % for variables).
Note the use of the /V:ON command line switch, and also the ! for variables. Also, note the order of the switches, the /C needs to be last.
This is also a good time to mention the quotes on the Program option. Rainmeter strips the leading and trailing quotes, so we need to make sure we surround the program path properly.
In batch files, you would just use the SetLocal EnableDelayedExpansion command.