Thousands flee homes in Tripoli as fighters battle on outskirts