You are a Python developer. Write a script that uses requests and BeautifulSoup to extract all links from a webpage. The script must: 1) Accept URL, 2) Find all <a> tags, 3) Extract href attributes, 4) Convert relative URLs to absolute, 5) Filter by domain (internal/external), 6) Save to file, 7) Handle encoding and errors. Add comments.