Yea of course thermodynamics works everywhere - as far as we know.
The hole in the ground suffers from a new problem. Your calculation depends on Faraday's relationship between electrical energy and volume of gas generated. That was done at 1atm pressure. At the bottom of the hole there's higher pressure, and you've said yourself that'll require more energy. Maybe it's not so much more that it breaks the idea, but unless you find out, you can't assume it's OK.
I know it sounds like I'm just making up a new silly excuse every time. But that's the nature of perpetual motion ideas - robbing from Peter to pay Paul, then robbing from John to pay Peter, then ... until you start to wonder if there's some fundamental roadblock that causes nature to always preempt your intentions and defeat them.