Or: Shouldn't immigration be good for capital?

I know they'd prefer for migrants to stay somewhere where their labor time is cheaper to make better use of unequal exchange, but how is it better to spend so many resources on turning away refugees and immigrants that are desperate to work for cheap, than to simply let them get exploited? What are the forces at play that make capitalists invest in border security so much? Is it simply to keep an implicit threat on the existing undocumented immigrant population to make them more precarious and more exploitable?