Some things to keep in mind for successful ENC scripts...
First, on the agent, run:
# facter fqdn
This is the node name that will be reported to the puppet master (equivalent to 'hostname -f'). If it doesn't match expectations, fix that first-- preferably via DNS, but /etc/hosts is a valid solution if necessary.
Other thing(s) to make sure of with your ENC code:
* don't output any text that isn't YAML
* don't return any exit code other than 0, unless you want your puppet runs to halt on ENC error
* Don't use tabs when generating your yaml. ;)
That means any debug text needs to go to stderr (or a log file), and you need exception handlers for everything.
And in the "probably obvious" category, I construct one large data structure in memory containing all the output I want in my YAML, and then dump that structure via a YAML library, rather than trying to format the output myself.