Confession was originally often made in public. Confessional secrecy is more about making it easier for people to freely confess their sins, free of the fear of retribution or shame, very much like why we have doctor-patient confidentiality enshrined in law today. I would imagine confessional secrecy arose very quickly, even if the norm wasn't private confession.
The first reference I could find for confessional secrecy was from a 4th century book written by the 3rd/4th century Persian bishop, Aphraates. In Demonstration VII, On Penance, he councils priests to keep a penitent's confessions secret, "lest he be exposed by his enemies and those who know him. .... If they reveal them to anyone, the whole army will suffer an adverse reputation."
Source: https://archive.org/details/bub_gb_Sy0vAAAAMAAJ/page/n251/mo... That's a Syriac to Latin translation. I used Google Translate for Latin to English. There's at least one partial English translation of that book online, but I found their translation more confusing.