Got it to work:
In wp-config.php I added:
define('W3TC_DYNAMIC_SECURITY', 'mysecretcode');
I created a PHP file (nocache.php) containing just the HTML to be output, and put it in the root folder. Then in my template file I used:
<!-- mclude mysecretcode nocache.php --><!-- /mclude mysecretcode -->