The reencoded string is doing two things differently:
=
is being reencoded to %3D
making your string 2 characters longer.
%20
is being reencoded as +
making the string 8 characters shorter (4 occurances)
The net difference is the 6 characters you are seeing.
Doing a simple str_replace like
$encoded = str_replace(["%3D", "+"], ["=", "%20"], $encoded);
Should resolve the problem in this case but both are valid representations of the encoding, I am curious as to why the length difference is a problem.