Oh, that extra carriage return does some weird stuff.
tl;dr: Something like this seems to work:
FOR /F %%L in ('wmic desktopmonitor get screenheight') DO (
CALL :foo "%%L"
IF NOT [%~1]== set RESULT=%~1
Anyway, the root of the problem, as you've noted, is wmic weirdly outputting those extra carriage returns. (It also throws in some spaces for good measure, but without "delims=" or something, those get thrown out by the for loop.) Ordinarily, FOR will just ignore blank lines, but for some reason, instead of the standard "\r\n" newline, wmic spits out "\r\r\n". And I guess FOR doesn't handle that sensibly.
Matter of fact, cmd in general doesn't handle that sensibly. I tried setting %%L to a temp variable and checking the temp variable with EnableDelayedExpansion, but it didn't work reliably; it seems that %var% will discard carriage returns, while !var! retains them. Go ahead, try and guess what output you'll get from this:
@ echo off
for /f %%a in ('wmic desktopmonitor get status') DO (
So thanks, you've given me a new weird thing to try to figure out in lieu of doing actual work!