Hate to ruin someone’s weekend! This is for Version 6.5.0_2da67da_2023.11.22.
It seems that mapproject coordinate transformation: lon,lat,height to X,Y,Z; then, running the reverse transformation : X,Y,Z to lon,lat,height yields something strange. Consider this example at the north pole.
Using these commands (presuming default WGS84 ellipsoid):
Had to read a bit about ECEF. As I understand, going from lon,lat,alt -> ecef is easy. The inverse is not, as you need (many) iterations and convergence to get precision. What does gmt do?