Test for file before closing it in destructor

Just stops confusing error messages when device open() fails.