To be a work for hire, a work must either be by an employee within the scope of their employment, or if by a contractor must meet three conditions:
1. it must be specially ordered or commissioned,
2. the written agreement with the contractor must explicitly say it will be a work for hire, and
3. it must fall into one of nine specific categories of works: (1) a contribution to a collective work, (2) a part of a motion picture or other audiovisual work, (3) a translation, (4) a supplementary work, (5) a compilation, (6) an instructional text, (7) a test, (8) answer material for a test, (9) an atlas.
Generally software fails on that third point. With software the copyright generally belongs to the contractor.
The employer can put something in the contract that requires the contractor to assign the copyright to the employer, but if the employer than breaks or cancels the contract the contractor has no need to do that.
Note: whether or not the person is an employee or contractor is determined by the common law of agency rather than by what the parties call their relationship.