Most command-line tools operating on files take filenames on command-line. Gnuplot scripts usually hard-code filenames in them -- because passing variables is rather unwieldy. Note the need for double-quoting, etc gnuplot -e 'inputname="foo.txt"' -e 'outputname="foo.png"' script.plg.
Perhaps, a variable -- or a function -- can be introduced to access the command-line arguments from inside? So that, instead of the above, one could say simply: gnuplot script.plg foo.txt foo.png? Easier to type, easier to place into Makefiles, and otherwise better...
Inside the plot-script, it would then be something like:
set output argv[2]
plot argv[1] 1:3
Have you looked at the -c command line flag?
For your example:
gnuplot -c script.plg foo.txt foo.png