def write_list(thelist, filename):
  """ write each element to a separate line in the file """
  try:
    fd = open(filename,'w')
  except IOError:
    print('Error opening file ' + filename)
    return []
  for list_el in thelist:
    fd.write(str(list_el) + '\n')
  return