Need to set tempfile to binary mode

Getting Encoding::UndefinedConversionError without this change.