With the America Invents Act (in 2011), the U.S. switched its method for adjudicating disputes about simultaneous inventions from "First to Invent" to "First to File". Prior to 2011, almost every country in the world (other than the U.S.) followed a "First to File" method for prioritizing ownership of an invention.
"First to Invent" (U.S. pre-2011) meant that if someone filed a patent application and you had already invented whatever they were claiming to invent, you could file your own application and leap-frog over their application. However, you had to prove that you came up with the invention before they did. That usually required submission of signed and dated laboratory notebooks. The problem with that system was that it incentivized the creation of falsified lab notebooks to steal someone else's invention. Also, it was time consuming and expensive to litigate the disputes over priority.
"First to File" is much simpler. It doesn't matter who was the first to come up with the invention, all that matters is whoever is the first one to file their application with the U.S. Patent & Trademark Office (or any recognized patent office worldwide).
As such, under "First to File" it is imperative that you keep your invention secret until after you have filed a disclosure with the patent office. "First to File" is also a bit more fair because "First to Invent" tended to favor the side with the best-paid legal team. You don't need any lawyers to prove you were the "First to File".