The story is figurative. It happened, but not necessarily in the way that the narrative lays out.
So, with that in mind, “why is the serpent in the garden?” kinda misses the point of the story, which is that our first human parents were tempted and fell to sin.
Again, since the narrative is in the literary genre of “prehistorical creation/origin mythology”, it has a number of narrative goals. One is to explain things that we know to be true, and give reasons for them. So, the answer to “why do serpents crawl on their bellies?”, in this narrative, is “because they tempted mankind into sin.”
As @Erundil points out, the context here is “true myth” – the truths found in Genesis 3 include Satan’s role as tempter, humanity and its penchant for sin, and the impact of sin on creation.