Since the original file (graphviz.pl) uses programming with side effects (failure driven loop in particular) to write to a file, the modified version that passes string around fails.
One idea to fix it is using assertz and retract instead of file IO.