I suspect the extra slash is coming from the str_replace action because normally there’s no need to manually add slashes when retrieving TAX urls.
Since you now end up with 1 unwanted slash, I would recommend testing situations with/without the slash. Starting with removing the one in the function definition. Make it empty, see what happens.
That is the first step to look into, in my opinion. I think this post might help you a bit as well: https://codex.wordpress.org/Debugging_in_WordPress