The concepts of "good and evil" have always existed in some form. It's just the dualistic nature of life (Life and death, pain and pleasure, health and sickness, wealth and poverty, good and bad). Humans encountered natural disasters (earthquakes, floods), wars with pillage and rape, disease, plagues, and infant mortality, man-made evil such as murders and theft, and of course, death.
As the ancients constructed their religious systems, the existence of "evil" had to be explained and rationalized, and I think blame transfer had something to do with it. The personification of a counter-god just made sense to many. If God was accredited with good things, then some other force had to be blamed for things they didn't want to lay at God's doorstep.
As with many things, the concept of the devil (Satan) just evolved and took it's place in religion. In folklore, it took on an image with red fiery eyes, horns, tail, and a pitchfork. I suppose the image was meant to steer people away from any connection with God's adversary. In time, I think it began to be used as a control tactic where this evil being lived in a domain of fire and torment, and if you didn't get in line, that's where you would end up. That's my summation anyway.