IO.write should write the encoded string when encoding is provided

IO.write when passed a encoding parameter should use that encoding to encode the string before writing it.

Added spec for IO.write with encoding should return the written exact bytes to the file