Handle exceptions when writing temp files.

IOError and OSError are handled when trying to write temp files in
file_to_directory() and directory_to_file() functions.

pkg_type is detected if the user gives the full path example:
`/etc/portage/package.license` will detect license as the pkg_type
without specifying.
--type will act as an override to automatic detection.

Since package type is detected automatically using the extension, the
--type switch will be used to override this detection, as a result
args.pkg_type no longer has a default value.