The 6th Amendment was written to prevent secret courts. The English Star Chamber was frequently secret and you could be put on trial without knowing what evidence/testimony was brought against you. The Star Chamber was also why the 5th Amendment exists.
https://en.wikipedia.org/wiki/Star_Chamber
https://en.wikipedia.org/wiki/United_States_Bill_of_Rights