Z Buffer File
There's no way to get this explicitly written to a file, but you can infer it
by using the atmosphere function. Here's how.
Turn off all lights except ambient. Set that to 255. Make all objects
white255. Set atmosphere on, with the near range being right at the camera and
the far range being just at the far extent of your scene. When you render this
scene to a file, the resulting file will be a grey-scale representation of the
z-buffer.
– G