You should never try to use undocumented variables to drive GSX, both because we might change them at any time ( we'll surely do as soon we'll have a better way in the SDK to interact with the Html menu ), but also because you cannot possibly know how the really work...because they are undocumented, and they are undocumented precisely for the above reasons.
The FSDT_GSX_MENU_OPEN is only a temporary variable that is used to trigger some communication between the Html menu, the GSX WASM module and the Couatl scripting engine that runs the actual GSX code, so it's just a (convoluted, but it's the only way), to allow interaction between the Html menu and Simconnect, which is not otherwise possible so, in your case, your effort to set the variable to something were nullified by the fact the GSX WASM module, as soon it recognizes the variable was set to 1, will immediately set it back to 0, together with a custom Simconnect event to communicate to GSX/Couatl the menu has been opened, so it's just a semaphore/mutex that works only in that direction.
In addition to that, you cannot open the GSX menu without it being already Active, which can only work if you open it first from the Toolbar menu OR if you end a flight with the icon Active, return to the main menu then start another flight, so the menu will automatically open on the 2nd flight.
If you try to set the variable to 1 when the toolbar icon is not Active ( dark ), nothing will happen. But if the toolbar icon is already Active, you can Open AND Close the menu with the HOTKEY so, considering you will still need to have the icon Active in any case, why not just using the Hotkey to open/close the menu ?
This method will be more reliable because, while we can possibly ( and we will, when possible ) change anything the way the menu works, we'll surely always have some hotkey.
Now, if you really want to go the fancy route and ignore my warning about your code being broken by future GSX updates, you can use the following expression to close the menu AS IF you clicked the X icon:
3 (>K:EXTERNAL_SYSTEM_TOGGLE)
But be warned, this can change at any time, that's why we never documented.