Line 48 is the issue:
$Mesh.rotation.y = lerp_angle($Mesh.rotation.y, atan2(move_vec.x, move_vec.z), delta * ang_accel)
When you don't press a button, move_vec will always be Vector3(0,0,0).
Because of that, atan2(move_vec.x, move_vec.z)
will always return 0. So the character will rotate to it's 0 rotation, when you don't press anything. You can solve this problem by putting, for example If move_vec.z != 0 or move_vec.x != 0:
before Line 48.