Mark was correct that it was some other code causing the issue. I tracked it down to a plugin I use during testing: Insert PHP; https://wordpress.org/plugins/insert-php/
There’s a line in the plugin’s code that’s replacing forward slashes.
Anyhow, I ran the same code I was trying yesterday via a shortcode, and everything works as expected.