You have asked a question that points towards the allegorical significance of this excellent short story. Clearly, the setting plays an immensely important part in the story. Note how Young Goodman Brown is said to leave his home and to head towards the forest, which is described in terms that make it ominous and foreboding, foreshadowing the evil sights that Goodman Brown will witness:
He had taken a dreary road, darkened by all the gloomiest trees of teh forest, which barely stood aside to let the narrow path creep through, and closed immediately behind. It was all as lonely as could be...
The forest is definitely described as an evil place, a place hidden from light and where evil acts can be perpetrated without others knowing. Thus it is a fitting place for Goodman Brown in his "present evil purpose." Of course, as he meets the Devil, and has to choose between heading on and turning back, the other characters that he sees, fine upright, good Christian folk (or so he thought) indicates one of the central themes in the story: the way that we are all tainted by evil, no matter how "good" we appear to be. Note how this is indicated by Goodman Brown's conversation with the devil about his family:
"They were my good friends, both; and many a pleasant walk have we had along this path, and returned merrily after midnight. I would fain be friends with you for their sake."
The setting and the charactes therefore help to advance Hawthorne's main message in this story: that evil is part of the essential human condition that cannot be ignored or covered up by masks of spiritual hypocrisy. It is this truth that Goodman Brown learns, and which, ironically, destroys the rest of his life as he commits himself to gloom and doom.