The variable order returned by FreeLink (FreeLink::get_vars() for C++, cog-free-variables for Scheme) depends on the variable names, not just the atom structure. For instance
scheme@(guile-user)> (cog-free-variables (And (Variable "$X") (Variable "$G")))
$6 = ((VariableNode "$G")
(VariableNode "$X")
)
scheme@(guile-user)> (cog-free-variables (And (Variable "$X") (Variable "$Y")))
$7 = ((VariableNode "$X")
(VariableNode "$Y")
)
I don't know if that's a bug, probably not, but it should at least be added as a warning in the pertinent documentations https://wiki.opencog.org/w/FreeLink https://wiki.opencog.org/wikihome/index.php/Scheme#cog-free-variables