Then Jerusalem and all Judea and all the region about the Jordan were going out to him, and they were baptized by him in the river Jordan, confessing their sins.
Matthew 3:5-6

Baptism serves two functions: wash away the uncleanness of sin and symbolize death to the old sinful life and resurrection to new life in righteousness. Confession of sins is a logical part of the process.