Avoid calling Write() if SelectForWrite() value has changed

This fixes bug #524.

Added a new unit test which fails in current version of EM. But with included fix to em.cpp, the test passes.