Use more current Ruby idioms and respect STDOUT/STDERR or pipelining.

* Added stdout/stderr to all calls to puts.
* Updated the Kernel#gets loop to explicitly use ARGF.
* Eliminate the use of special globals ($ variables).
* Use more appropriate exit code for Errno::EPIPE errors.