The issue is that the dlg vars are using core pv buffers to copy their value before returning it. I assume they do the copy to avoid future race with their shared memory location, by cloning in pv buffers.
A quick solution is to increase pv_buffer_slots value:
* https://www.kamailio.org/wiki/cookbooks/5.1.x/core#pv_buffer_slots.
Must be more than the number of dlg vars you use in the string.
I will think to see if this can be avoided somehow in the dialog module.