input: Write a python function to scrape data from a given URL and write the retrieved data to a file named 'scraped_data.txt'.
  assert scrape_and_write_data('http://example.com', 'p') == True
  assert scrape_and_write_data('http://anotherexample.com', 'div') == True
output: import requests
  from bs4 import BeautifulSoup
  
  def scrape_and_write_data(url, tag):
      try:
          response = requests.get(url)
          response.raise_for_status()
          soup = BeautifulSoup(response.content, 'html.parser')
          elements = soup.find_all(tag)
  
          with open('scraped_data.txt', 'w', encoding='utf-8') as file:
              for element in elements:
                  file.write(element.get_text() + '\n')
          
          return True
      except Exception as e:
          return False