The purpose of an ERB template is to generate strings consisting of zero or more static parts and one or more dynamic parts. They are otherwise a poor vehicle for embedding general-purpose Ruby code in your manifests. In particular, you do not normally want to perform explicit I/O in a template.
You certainly don't want to perform I/O to or from the standard streams,
as these should not be connected/open when the template is evaluated. It's not clear to me whether the I/O you are doing is your actual objective (in which case a template is the wrong tool -- use generate() or a custom function instead) or whether it's just your attempt at implementing what you're really after.
Also, it is essential to understand that all Puppet DSL functions, including inline_template(), are executed on the master during catalog compilation, whereas resources, including Execs, are applied to client nodes. As such, if a DSL function drops a file on the local file system, resources cannot normally expected to consume that file because their local file system at application time is normally a different one.
Here's a trivial example of how an inline template might be used:
$foo = 'one two three four five'
$moddedContent = inline_template("<%= @foo.gsub(/one two three/,'') %>")
notify { 'inline_template demo':
message => "The modified content is $moddedContent"
}
# Yields "The modified content is four five"
Of course, an experienced Puppeteer would never do that particular job via inline_template(), because the regsubst() function can more clearly, succinctly, and cheaply express the same thing:
$moddedContent = regsubst($foo, 'one two three', '')
John