A new education law that has inspired lawsuits from school districts and derision from teachers’ unions nearly fell victim to an intra-party feud in the Republican-led state Senate, as detailed in a series of text messages exchanged by legislators and their staff during the hectic final days of the 2017 legislative session.