Use binmode to write image properly