Handler frame_change_pre doesn't work in render
The answer is similar to this question. Though all this is new from 2.81.
So here are some little more information (as far as I understand all this, which seems to be new thing along the current versions).
To make your script work, you can change it to:
import bpy

def frame_handler(scene, depsgraph):
    #print(depsgraph)
    obj = scene.objects['Cube']
    obj = obj.evaluated_get(depsgraph)
    scene.objects['Text'].data.body = '{0:.2f}'.format(obj.location.z)

bpy.app.handlers.frame_change_post.clear()
bpy.app.handlers.frame_change_post.append(frame_handler)

Here frame_change_post is used. But following this documentation:

This can be used, for example, to alter scene prior it gets rendered.

So the result will be what you want to do.
In the script above I've changed the rounding for Z. That allows to confirm that 'post' is before rendering. If object Z position is 10 at frame 10, the text object will display 10 at the same frame.
Additionally, depsgraph is for dependencies graph. That means a data provided in the API to take into account the fact that during animation (or others) the object state varies due to what it depends on.
frame_change_pre has no depsgraph parameter in 2.82.