For He made Him who knew no sin to be sin for us, that we might become the righteousness of God in Him.
(2 Corinthians 5:21) NKJV
God can’t abide sin, he can’t look on it. Yet in order for free will to be a possibility, sin has to be possible. How does a perfectly pure and righteous God create a system which allows evil to exist? He has to go against his own nature and become sin for us.
The Earth was created within a physical system which had already fallen. The fall of creation was the command let there be light, which caused formerly pure water of the deep to become impure. This was when God the Son, Jesus Christ, became sin for us.
How could a corrupted world be described as very good, or perfect? Perfect means lacking nothing. The corrupted universe lacked nothing. It was perfectly suited to carry out its purpose.