Thousands of foreigners flee 'chaotic' Libya