At first, God told some of His men what to write, & charged the Levites with preserving the writings. This continued thruout Old Testament times, after the Levites became part of the Jews. God caused them to keep what He had chosen to become the Old Testament before Jesus came. Not much question about OT canon.
As for the New Testament, God used certain "councils" of early church fathers, etc. to make it. He caused them to choose most of the known writings of the apostles that conform with one another. ( Several scholars attribute more writings from Paul which weren't chosen for the canon, as they didn't proclaim any doctrine, nor were instructive.) Other early Christian writings generally don't conform with the ones that were placed in Biblical canon.
We must TRUST GOD to have placed what He wanted in the canon.