The state schools most in need of teachers are struggling to retain them, as forecasts indicate the shortage will only get worse.