Then why did God purposefully create a written source (the Bible) that portrays Himself as immoral ?
Maybe the God in the Bible isn't the God that exists? Even if the Bible is of supernatural origin the only reason you have to believe it's the word of God and not some sinister devilment is the Bible's say-so.
Once again, IF God IS, then whatever He does is righteous
Repeating that isn't going to make it true. Just because God is the arbiter of morality doesn't make his every action moral. The act of making a moral code sets the code as a higher authority than God's will. Otherwise it's not a moral code, but an immoral one.