Modify this function to work properly - 
def scrape_practo_psychologists(cities, designations):
    headers = {
        "User-Agent": (
            "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
            "AppleWebKit/537.36 (KHTML, like Gecko) "
            "Chrome/58.0.3029.110 Safari/537.3"
        )
    }

    all_doctors = []

    for city in cities:
        for designation in designations:
            base_url = f"https://www.practo.com/{city}/{designation}"
            page = 1  # Start from the first page

            while True:
                # Construct the URL for the current page
                if page == 1:
                    url = base_url
                else:
                    url = f"{base_url}?page={page}"

                print(f"Scraping Page {page}: {url}")
                response = requests.get(url, headers=headers)

                # Check if the request was successful
                if response.status_code != 200:
                    print(f"Failed to retrieve page {page}. Status code: {response.status_code}")
                    break

                soup = BeautifulSoup(response.content, "html.parser")

                # Find all doctor cards on the current page
                doctor_divs = soup.find_all("div", class_="u-border-general--bottom")

                # If no doctor cards are found, assume we've reached the last page
                if not doctor_divs:
                    print(f"No doctor entries found on page {page}. Ending scraping.")
                    break

                # Iterate through each doctor card and extract details
                for index, div in enumerate(doctor_divs, start=1):
                    # Extract doctor's name
                    name_tag = div.find("h2", attrs={"data-qa-id": "doctor_name"})
                    name = name_tag.get_text(strip=True) if name_tag else "N/A"

                    # Extract address
                    locality_tag = div.find("span", attrs={"data-qa-id": "practice_locality"})
                    city_tag = div.find("span", attrs={"data-qa-id": "practice_city"})
                    locality = locality_tag.get_text(strip=True).rstrip(',') if locality_tag else ""
                    city = city_tag.get_text(strip=True) if city_tag else ""
                    address = f"{locality}, {city}" if locality and city else "N/A"

                    # Extract consultation fee
                    fee_tag = div.find("span", attrs={"data-qa-id": "consultation_fee"})
                    fee = fee_tag.get_text(strip=True) if fee_tag else "N/A"

                    # Append the extracted data to the list
                    all_doctors.append({
                        "Name": name,
                        "Address": address,
                        "Consultation Fee": fee,
                        "City": city,
                        "Designation": designation
                    })

                    print(f"Scraped Doctor {len(all_doctors)}: {name}, {address}, {fee}")

                # Move to the next page
                page += 1
                time.sleep(1)  # Delay to be polite and avoid overloading the server

    csv_file = "practo_doctors.csv"
    file = open(csv_file, "w")

    # Save the scraped data to a CSV file
    writer = csv.DictWriter(file, fieldnames=["Name", "Address", "Consultation Fee", "City", "Designation"])
    try:
        with open(csv_file, "w", newline='', encoding="utf-8") as file:
            writer.writeheader()
            writer.writerows(all_doctors)
        print(f"\nSuccessfully saved data to {csv_file}")
    except Exception as e:
        print(f"Error writing to CSV file: {e}")

Here the first for loop is  working properly so dont touch it or change it, but the saving part is having some issue, and also im getting some NA entries so it those can be avoided in final csv, would be great. currently got an error - 
Error writing to CSV file: 'charmap' codec can't encode character '\u20b9' in position 41: character maps to <undefined>.

Give me a more optimized working function for my task which is majorly error or bugs free.