Fix writing to a non existent path

raise IOError when trying to write a file in a directory that does not
exist.

Signed-off-by: Jordi Carrillo <jordilin@gmail.com>