It’s definitely not modern slavery in the literal sense, because indeed it’s fully legal for them to leave or quit as they wish, but neither is it fully true to say that they are free to do so.
If an H-1B worker does quit their job, or even if they get fired, they have a very tight deadline under the immigration laws to depart the country. This applies regardless of what financial obligations they may have as a renter or homeowner and regardless of the situation of the rest of their family.
And if after their job ends they rush out of the country to meet the immigration deadline, any lingering ties to the US will make it harder for them to convince CBP to let them re-enter on visitor status, so the departure may in some circumstances be either temporarily or permanently one-way as well as rushed.
The severity of this disruption forces many H-1B workers to meekly put up with a lot more abuse and mistreatment at work than must US citizens, LPRs, and those lucky few categories of nonimmigrants whose work authorizations are not tied to their employment. Agreed, it’s not slavery, but it’s not full freedom either.
A more humane approach would be what Canada does: holders of Canadian employer-specific work permits who quit or lose their job are legally allowed to remain in Canada until their current work permit expires, although not to work for a different Canadian employer without first receiving a new permit. They can rely on this predictability of legal status in the country when signing leases, planning their children’s education, and other matters. And it often gives them far more time than the tight US deadline if they want to find a new employer who agrees to sponsor a subsequent work permit for them.