Tried it here and it worked, both on Arch Linux with OCaml 4.01.0 and a clean Ubuntu/12.04 with OCaml 3.12.1:
$ ocaml graphics.cma test.ml
Debian splits OCaml into two packages: ocaml-nox (no X) and ocaml (everything). Make sure you're not using the nox version, and make sure you have an X server available (i.e. you're not running it on a headless server or something).
Still, "fatal I/O error" is a terrible error message.