The documentation of CreateDesktopEntry says: "desktop entry is stored [...] in the location specified in $XDG_DATA_DIRS/applications or $XDG_DATA_HOME/applications, including the default paths for both, as defined by freedesktop.org." But the desktop entry is always created in default folder i.e. ~/.local/share/applications if installed locally.
While it makes sense that the desktop entry is created in where the operating system looks for it, the documentation gives impression that the env variables have some effect.
To reproduce, create the attached example installer, set XDG_DATA_HOME env variable and run installer.