Thousands flee to beaches as fires encircle Australian towns