Write UTF-8 encoded text inside binary file in Python

content = "MASBicudo"
bytes_utf8 = content.encode("utf-8")
with open("filename.txt", "wb") as fs:
    fs.write(bytes_utf8)

str has the encode method, that returns bytes with the encoded string.