If the Web Part derives from Microsoft.SharePoint.WebPartPages.WebPart, and does not use features from System.Web.UI.WebControls.WebParts.WebPart, such as the System.Web.UI.WebControls.WebParts.PersonalizableAttribute, it serializes as a *.dwp file.
If the Web Part derives from System.Web.UI.WebControls.WebParts.WebPart, or derives from Microsoft.SharePoint.WebPartPages.WebPart, but does use certain key features from System.Web.UI.WebControls.WebParts.WebPart, then it serializes as a *.webpart file.