SI-5717 error when bytecode cannot be written

If there's an existing file foo when emitting a class file for foo.Bar,
then emit an error at foo.Bar, similar to what javac does.

The error message looks something like:

foo.scala:4: error: error writing object Foo: ./mypkg/Foo.class: ./mypkg is not a directory

This is a non-destructive version of https://github.com/scala/scala/pull/1746

It's worth quoting https://github.com/scala/scala/pull/2258

"We don't need to assert our way out of tight spots, we can issue an error."

Review by @paulp who went this way before.