The short answer is that this is because the first equation is just a limiting case of the second.
The first equation is and approximation for the potential energy due to gravity near the Earth's surface. This equation is a limiting case of of Newton's universal law of gravity(the first equation), if we assume we are near the Earth's surface.
Let [itex]R=R_e+h[/itex] where Re is the radius of the Earth, and h is your height above the Earth.
Now,
[tex]U=GM_em\frac{1}{R_e+h}[/tex]
Since h is really small compared to R_e(we are close to the Earth's surface), we can Taylor expand the fraction and keep only the first few terms:
[tex]U=GM_em\frac{1}{1+h/R_e}=GM_em\frac{1}{R_e}(1-h/R_e)[/tex]
We get two terms, but we can drop the first, as it is a constant, and constants of potential energy don't matter. Let's drop that constant. (This is equivalent to setting the Earth's surface as 0 potential.)
So,[tex]U=-GM_em\frac{1}{R_e^2}(h)=-mgh[/tex]
with [itex]g=\frac{GM_e}{R_e^2}[/itex]
So, near the Earth's surface, both equations must give similar values, because the second is just an approximate limiting case of the first.