All prophets of Allah (swt) are infallible and invulnerable to sin, and what Prophet Adam (pbuh) did was that he simply didn’t take heed in Allah's (swt) advice, which is not considered true disobedience. The truth of the matter is that Prophet Adam (pbuh) and all people coming to this world was something predetermined by divine decree and Allah's (swt) will. At the same time, this world is only a place for us to be evaluated, not a means of punishment.
What Allah (swt) intended by sending Prophet Adam (pbuh) and his children down to the earth, was to send them to a place where good and bad actions were both possible (unlike heaven that is only a place of good deeds) and test them. If they were successful in following his commands while at the same time being capable of disobeying Him, He would reward them and even grant some of them like his prophets higher ranks than His close angels. Hence, we must first become earthly to be able to become heavenly.
The story of creation is an interesting and enlightening one that can be found in books of every religion. From the perspective of Islam and hadiths, the story the Torah and Gospel narrate has several problems. On the other hand, the real story has been mentioned in the Quran in the most beautiful and precise way.
There are some significant points here that can be useful in answering your question:
1. Prophet Adam (pbuh) was one of Allah’s (swt) great prophets, thus being infallible from sin, therefore whatever he ever did surely wasn’t a sin (even if it may seem so in some cases). Someone asked Imam Ridha (as): "Are prophets infallible?" He replied: "Yes." “Then why does God say that Prophet Adam sinned?” He asked again. The imam answered: “Fear Allah (swt) and don’t impute corrupt acts to prophets. Allah (swt) did not create Prophet Adam (pbuh) to stay in heaven but to be his vicegerent in this world and his disobedience was in heaven, not in this world…” .
Regarding this hadith Allamah Tabatabai has said: “The Imam said that he disobeyed God in heaven, indicating that not eating from that specific tree was an irshadi ruling and not a mowlawi one because no divine rulings had been legislated in heaven and it was after Prophet Adam (pbuh) came to this world, which was inevitable due to Allah's will, that Allah's (swt) decrees were legislated. So he disobeyed an irshadi command instead of a mowlawi one, meaning that Allah (swt) wanted to inform him of how harmful following Shaytan was, and he eventually learned the hard way; he suffered the consequences; exactly like when a father advices his son not to walk barefoot because a nail might hurt his foot. Prophet Adam (pbuh) and his spouse did themselves an injustice and were banned from heaven but didn’t sin against Allah (swt) by disobeying him. Besides that, if he had really sinned he should have been sent back to heaven after sincerely repenting to God for true repentance erases all effects and traces that a sin can have, but that wasn’t the case for him and he didn’t return. This proves that the forbiddance was not mowlawi, which as a result would make him a sinner, but simply advice by Allah (swt) out of His benevolence.
Of course, not only is this materialistic world a place where desires collide, making sinning possible, but the nature of man himself entails the possibility of sinning for him, because he is a combination of intellect and bodily desire.
2. Prophet Adam’s (pbuh) descending from heaven was not optional but rather a matter of divine decree and destiny, therefore even if he hadn’t eaten from the forbidden fruit, he still would have descended. This is something Imam Ridha (as) directly points to in a hadith.
Allamah Tabatabai says: “Based on the style of expression and context, the verses in the Quran relating to this story imply that man was meant to live and die in this world, therefore, putting him in heaven (not the eternal heaven) was only temporary to test him.”
In a narration from Imam Baqir (as), the imam says: "By Allah (swt) Prophet Adam was created for this world."
3. What must be taken into consideration is that coming to this world isn't punishment and that by coming to this world one gets the opportunity to practice and eventually improve and perfect himself and finally reach the climax in which the holy and spiritual stand at. Allah (swt) has created us higher and greater than his angels and has made us his vicegerents in this world. When the angels complained against man, Allah (swt) defended him and told them: “I know what you know not” (انی اعلم ما لا تعلمون).
All of this is only because man consists of intellect and desire while angels purely intellect. If such a creature abides by his lord's rulings he is certainly far more superior to a creature that unconsciously does so and this excellence can only be accomplished by being in a situation where one needs to choose between intellect and ignorance; this world is such a place. Thus we should be thankful of Allah (swt) for the blessing of coming to this world as we can become heavenly through this becoming earthly.
 A mowlawi command is one who disobeys it deserves to be punished, on the other hand, an irshadi command isn't actually a command that must be followed and is more of a form of advice, thus one who doesn’t heed doesn’t deserve punishment.
 Seyyid Mohammad Hosein Tabatabai, Al-Mizan (farsi translation), vol. 1, pg. 219.
 Ibid, pg. 201.
 Imam Ali (as) says: “Allah (swt) created the angels with intellect and without any desire and animals with desire and without intellect, but He created man with both so that if he listens to his intellect, he goes higher than angels and if he listens to his desires, he will be lower than animals.” Saduq, Ilalul-Sharaye’, pg. 15, chapter 6.
 There is a hadith that says: “His disobedience was in heaven, not on earth; and was something that was divine decree.”
 Seyyid Mohammad Hosein Tabatabai, Al-Mizan (farsi translation), vol. 1, pg. 196.
 Ibid, vol. 1, pg. 225.