I am trying to calculate the mass of a planet by the following image
I have the mass of the object, $2$ kg, and the radius of the planet, $5000$ km (also the gravitational constant $G$). My first attempt was to calculate the variation of the potential energy with the classical formula, taking any point of the graph ($h = 10$ m and $E_p = 40$ J for instance)
$$ U_G(r) = -\frac{GMm}{r} $$
But trying to get $M$ is giving me the wrong result with this method.
Looking to the correct answer, the author is using the simplified formula
$$ U_G = mgh $$
But I have no clue of why this works and the normal method not. In my attempt I got a mass of $1.5 \cdot 10^{18}$ kg, and the answer is $7.5 \cdot 10^{23}$ kg.