Bulk insert M:N relation in PostgreSQL
You have all the information you need to populate the new database from the old one with 4 insert statements:

create table team_ids (id serial, name TEXT)

insert into team_ids (name)
select distinct supervisor_name from employee

-- now supervisors have ids assigned by "serial" type

insert into person (id, name, old_ident)
select ident, name, ident from employee
union
select ident, supervisor_name, ident from employee

insert into team (id) -- meh
select id from team_ids

insert into teammember (person_id, team_id, role)
select e.ident, t.id, 'e')
from employee as e, join team_ids as t
on t.name = e.supervisor_name
union -- and, I guess
select t.id, t.id, 'm')
from team_ids as t


You may have to adjust to taste.  I'm assuming employee.ident can be mapped onto person.id, and that your DBMS allows assigning values to columns with auto-generated values.  Except for that, it's just basic SQL, nothing fancy and, of course, no loops.

Additional commentary:


The 'team' table might be (more conventionally) renamed to department.
A SERIAL (with its 2 billion possibilities) should be plenty, no need for a BIGSERIAL.
There appears to be no database mechanism to enforce 1:1 cardinality of manager to team. Doesn't every team need a leader, by definition? Is there not a CHECK or FOREIGN KEY constraint for teammember.role? Perhaps the question simplified these details away.
The "teammember" table name would more conventionally have a word boundary, for example TeamMember or team_member.